﻿@using FlowBasisSampleSite.Domain.Entities
@{
    ViewBag.Title = "Permissions";

    List<Permission> permissions = ViewBag.Permissions;
}

<h2>Permissions</h2>

<div id='query-div'>
    <input data-json-input-name='matchText' type="text" style='width: 250px' />
</div>

<div id='permission-pager'></div>
<div id='permission-list'></div>

<script type="text/javascript">//<!--

    var permissionResultSet = new FlowBasis.Data.RemoteResultSet({
        url: "~/Admin/Permissions/GetPermissionList",
        query: {},
        maxResultsPerRequest: 100
    });

    var resultSetList = new FlowBasis.Data.ResultSetList({
        container: "#permission-list",
        resultSet: permissionResultSet,

        paging: {
            resultsPerPage: 20
        },

        itemConverter: function (item) {
            var listItem = jQuery("<li>");

            listItem.append(
                jQuery("<a>")
                    .attr({ href: FlowBasis.resolveUrl("~/Admin/Permissions/Info") + "/" + item.id })
                    .text(item.name)
            );

            return listItem;
        }
    });

    var resultSetPager = new FlowBasis.Data.ResultSetPager({
        container: "#permission-pager",
        resultSetList: resultSetList,
        hideIfOnlyOnePage: true
    });

    var queryInput = new FlowBasis.UI.JsonForm({ container: "#query-div" });

    function searchPermissions() {
        var newQuery = queryInput.getInputData();
        permissionResultSet.updateQuery(newQuery);
    }

    var debouncedSearchPermissions = _.debounce(searchPermissions, 300);

    jQuery(queryInput).bind("inputDataChanged", function () {
        debouncedSearchPermissions();
    });

//--></script>
